package org.jeecg.modules.seq.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.seq.entity.Sequence;
import org.jeecg.modules.seq.mapper.SequenceMapper;
import org.jeecg.modules.seq.service.ISequenceService;
import org.springframework.stereotype.Service;
import java.util.concurrent.locks.ReentrantLock;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author
 * @since 2020-10-09
 */
@Service
public class SequenceService extends ServiceImpl<SequenceMapper, Sequence> implements ISequenceService {

    private ReentrantLock lock = new ReentrantLock();

    @Override
    public Long nextVal(String sequenceName) {
        Long seqVal = null;
        lock.tryLock();
        try {
            seqVal = this.baseMapper.nextVal(sequenceName);
        } finally {
            lock.unlock();
        }
        return seqVal;
    }
}
